/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package MyClass;

import java.util.Random;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.TiledLayer;

/**
 *
 * @author HuuTai_it
 */
public class Islands extends TiledLayer {
    
    public Islands (GameManagement gameMng, Image image) throws Exception {
        
        super(10, 10, image, 24, 24); 
        
        Random r = new Random();
        
        int numIslands = Math.abs(r.nextInt() % 4);
        if(gameMng.control.difficulties == 1)
            numIslands += 7;  
        else
            if(gameMng.control.difficulties == 2)
                numIslands += 5; 
            else
                numIslands += 2;
        
        for(int i = 0; i < 10; i++)
            for(int j = 0; j < 10; j++)
                setCell(j, i, 0);
        
        for(int i = 0; i < numIslands;)
        {            
            int x = Math.abs(r.nextInt() % 10);
            int y = Math.abs(r.nextInt() % 10);
            while(gameMng.element[x][y] != 0)
            {
                x = Math.abs(r.nextInt() % 10);
                y = Math.abs(r.nextInt() % 10);
            }
            
            if(gameMng.element[x][y] == 0)
            {
                setCell(x, y, Math.abs(r.nextInt() % 2) + 1);
                gameMng.element[x][y] = 1;
                i++;
            }
        }
    }   
}
